<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>11、属性指令-v-bind.html</title>
</head>
<body>

<div id="app">
    <div v-for="(value,key,index) in yingshous">
        {{key}}：
        <div style="margin-left: 20px;">
            <div v-for="(data,index) in value">
                <span>{{data.month}}==={{data.money}}</span>
            </div>
        </div>
    </div>
    <hr>
    <div v-for="(value,key,index) in yingshous">{{key}}：
        <div style="margin-left: 20px;">
            <div v-for="(value,key,index) in transferdata(value)">
                <span>{{key}}==={{value}}</span>
            </div>
        </div>
    </div>
</div>

<script src="js/vue.global.js"></script>
<script>
    var vue = Vue.createApp({
        data() {
            return {
                yingshous: {
                    "2019": [{month: 1, money: 54545}, {month: 4, money: 54545.23}],
                    "2020": [{month: 1, money: 54545}, {month: 6, money: 54545.23}],
                    "2021": [{month: 1, money: 54545}, {month: 9, money: 54545.23}],
                    "2022": [{month: 1, money: 54545}, {month: 11, money: 54545.23}]
                }
            }
        },
        methods: {
            transferdata(arr) {
                // 对象容易判断，
                var obj = this.arrtoObj(arr);//{1: 54545, 4: 54545.23}
                for(let i=1;i<=12;i++){
                    if(!obj[i]){
                        obj[i] = 0;
                    }
                }
                return obj;
            },
            arrtoObj(arr) {
                var obj = {};
                for (let i = 0; i < arr.length; i++) {
                    obj[arr[i].month] = arr[i].money;
                }
                return obj;
            }
        }
    }).mount("#app");
</script>

</body>
</html>